#include "testdesfrm.h"
#include "ui_testdesfrm.h"

TestDESFrm::TestDESFrm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TestDESFrm)
{
    ui->setupUi(this);
}

TestDESFrm::~TestDESFrm()
{
    delete ui;
}

void TestDESFrm::on_btn_encrypt_clicked()
{
    if(ui->lineEdit_key->text().isEmpty()){
        ui->lineEdit_key->setFocus();
        return;
    }

    if(ui->textEdit_encrypt->toPlainText().isEmpty()){
        return;
    }

    //QByteArray buff ="Er1uMTssTRszHZ3tU7Ro3BGT669SOm1FozqLnA8U3nH3m+MKiVlFl6Hyi9f5wENOsaw2GB7R5tYAAunJ4GNObZxlfIeezJM3MrRc4Pc8/zY=";
//    //    qDebug() << 0<<buff;
//        QString str = des.decrypt(QByteArray::fromBase64(buff),  QByteArray("shinow90"));
//        qDebug() << 1<<str.toUtf8();
//        qDebug() << 2<< des.encrypt(str.toUtf8(), QByteArray("shinow90")).toBase64();

    ui->textEdit_decrypt->setText(Des.encrypt(ui->textEdit_encrypt->toPlainText().toUtf8(),ui->lineEdit_key->text().toUtf8()).toBase64());
}

void TestDESFrm::on_btn_cls_encrypt_clicked()
{
    ui->textEdit_encrypt->setText("");
}

void TestDESFrm::on_btn_cls_decrypt_clicked()
{
    ui->textEdit_decrypt->setText("");
}

void TestDESFrm::on_btn_decrypt_clicked()
{
    if(ui->lineEdit_key->text().isEmpty()){
        ui->lineEdit_key->setFocus();
        return;
    }

    if(ui->textEdit_decrypt->toPlainText().isEmpty()){
        return;
    }
    ui->textEdit_encrypt->setText(Des.decrypt(QByteArray::fromBase64(ui->textEdit_decrypt->toPlainText().toUtf8()),ui->lineEdit_key->text().toUtf8()));
}
